1. Field of the Invention
The present invention generally relates to memory management. More particularly, the present invention provides a method, system, and computer program product for detecting performance-degrading memory management anti-patterns, particularly in systems with automatic storage reclamation (“garbage collection”).
2. Related Art
A pattern is a common solution to a problem that occurs in many different contexts. Patterns capture expert knowledge about “best practices” in software design in a form that allows that knowledge to be reused and applied in the design of many different types of software. Anti-patterns are conceptually similar to patterns in that they document recurring solutions to common design problems. They are known as anti-patterns because their use (or misuse) produces negative consequences. Anti-patterns document common mistakes made during software development as well as their solutions. Anti-patterns address software architecture and design as well as the software development process itself.
When an object is created in an object-oriented software environment such as Java, the memory to contain the object (and any objects that it contains) must be allocated from the heap and any initialization code for the object and the contained objects must be executed. When the object is no longer needed, necessary clean-up must be performed and the reclaimed memory must be returned to the heap to avoid “memory leaks.” While the overhead for creating and destroying a single object may be small, when a large number of short-lived objects are frequently created and then destroyed (also referred to as “object churn”) the performance impact may be significant, and memory leaks resulting in out-of-control memory growth may occur. This type of excessive dynamic allocation anti-pattern, therefore, should be detected and refactored (restructured or reorganized) to overcome its negative consequences.
Known solutions for detecting performance-degrading memory management anti-patterns generally comprise weak, informal methods that rely on the skill and insight of one or more highly skilled analysts poring through the output of a memory debugging tool or raw heap dumps looking for unexpectedly retained objects. A common strategy involves running a system for a period of time, performing garbage collection, taking a baseline snapshot of the heap (H1), and running a test case to completion. After completion of the test case, garbage collection is again performed and a second snapshot of the heap (H2) is taken. Objects present in the second snapshot of the heap (H2) that are not present in the first snapshot of the heap (H1) are candidate “memory leaks,” i.e., objects possibly retained that the garbage collection system cannot prove are reclaimable but that nonetheless will not contribute to the future of the computation. This process is illustrated in the graph 100 of FIG. 1, in which a candidate memory leak has been detected using the H2-H1 snapshot comparison method described above.
Procedures based on this strategy can only detect long-lived unnecessary object retention. Another class of memory management problems (uncontrolled heap growth) arises from short-lived object retention due, for example, to object churn and other transient memory requirements that increase process size (footprint) and related processing costs. As illustrated in the graph 100 of FIG. 1, the H2-H1 snapshot comparison method will show no net growth in the size of the heap in such cases (no new objects in the second snapshot relative to the first) and therefore will not detect this problem. It should be noted that a heapdump is not a complete dump of all the objects. Some objects are held in a thread-local cache temporarily. This and asynchronous garbage collection contribute to the noise level for determining whether an out-of-control memory growth situation is at hand and make the need for a new solution apparent.
Accordingly, a new solution is required to: (1) address the increasingly rare skill set that is required to analyze program behaviors to detect and repair memory management anti-patterns; (2) minimize the time required to detect memory management issues, analyze their root cause, and eliminate them in software development environments; and (3) provide for the deployment of analytic tools in production environments to enable fast, automatic identification of the root cause of memory growth.